package org.dna.wickwtui;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.dna.uimodel.MenuItem;
import org.dna.wickwtui.activities.ManageActivityPage;
import org.dna.wickwtui.users.ManageUserPage;

public class MenuPanel extends Panel {
	private static final long serialVersionUID = 1L;

	@SuppressWarnings( { "serial", "unchecked" })
	public MenuPanel(String id) {
		super(id);

		List<MenuItem> menu = Arrays.asList(
				new MenuItem("Activities",ManageActivityPage.class){
                    @Override
					public Component createMenu() {
						Link link = new Link("link") {

							@Override
							public void onClick() {
								getParent().add(new SimpleAttributeModifier("id", "current"));
								setResponsePage(new ManageActivityPage());
							}
						};
						link.add(new Label("caption", getCaption()));
						return link;
					}
				}, 
//				new MenuItem("New activity", ManageActivityPage.class), 
				new MenuItem("Users", ManageUserPage.class) {
                    @Override
					public Component createMenu() {
						Link link = new Link("link") {

							@Override
							public void onClick() {
								MarkupContainer mkc = getParent(); 
//								mkc.setMarkupId("current"); //used to highligth the current selection
								mkc.add(new SimpleAttributeModifier("id", "current"));

								setResponsePage(new ManageUserPage());
							}
						};
						link.add(new Label("caption", getCaption()));
						return link;
					}
				});

		ListView lv = new ListView("menu", menu) {
			@Override
			protected void populateItem(ListItem item) {
				MenuItem menuitem = (MenuItem) item.getModelObject();
				item.add(menuitem.createMenu());
			}
		};
		add(lv);
	}
}

